<template>
  <div class="app-container">
    <el-tabs v-model="tabIndex" @tab-click="resetQuery">
      <el-tab-pane label="客户汇总" name="0"></el-tab-pane>
      <el-tab-pane label="收支汇总" name="1"></el-tab-pane>
      <el-tab-pane label="收支明细" name="2"></el-tab-pane>
    </el-tabs>
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="交易账号" prop="accountInfo">
        <el-input v-model="form.accountInfo" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input v-model="form.customerName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="时间范围" prop="time">
        <el-date-picker v-model="form.time" type="daterange"
                        start-placeholder="开始日期" end-placeholder="结束日期"  value-format="yyyy-MM-dd" clearable></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-show="tabIndex==0"
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="saleUserName" label="销售员" align="center"/>
      <el-table-column prop="customerName" label="客户名称" align="center"/>
      <el-table-column prop="disable " label="是否启用" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.disable"/>
        </template>
      </el-table-column>
      <el-table-column prop="lastTime" label="最新时间" align="center"/>
      <el-table-column prop="paymentType" label="结算方式" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ims_payment_type" :value="scope.row.paymentType"/>
        </template>
      </el-table-column>
      <el-table-column prop="incomes" label="收款(元)" align="center" width="150"/>
      <el-table-column prop="debt" label="欠款(元)" align="center" width="150"/>
    </el-table>
    <el-table
      v-show="tabIndex==1"
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="statisticTime" label="统计时间" align="center"/>
      <el-table-column prop="paymentMethod" label="交易方式" align="center" width="100"/>
      <el-table-column prop="accountInfo" label="交易账号" align="center"/>
      <el-table-column prop="customerName" label="客户名称" align="center"/>
      <el-table-column prop="customerAccount" label="客户账号" align="center"/>
      <el-table-column prop="totalIncome" label="总收入金额(元)" align="center" width="150"/>
      <el-table-column prop="totalExpense" label="总支出金额(元)" align="center" width="150"/>
      <el-table-column prop="netAmount" label="净额(元)" align="center" width="150"/>
    </el-table>
    <el-table
      v-show="tabIndex==2"
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="transactionNo" label="交易编号" align="center"/>
      <el-table-column prop="status;" label="交易状态" align="center" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_trade_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="交易时间" align="center"/>
      <el-table-column prop="transactionType" label="交易类型" align="center" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_trade_type" :value="scope.row.transactionType"/>
        </template>
      </el-table-column>
      <el-table-column prop="relatedOrderNo" label="关联单号" align="center"/>
      <el-table-column prop="paymentMethod" label="交易方式" align="center" width="100"/>
      <el-table-column prop="accountInfo" label="交易账号" align="center"/>
      <el-table-column prop="customerName" label="客户名称" align="center"/>
      <el-table-column prop="customerAccount" label="客户账号" align="center"/>
      <el-table-column prop="amount" label="交易金额(元)" align="center" width="100"/>
      <el-table-column prop="remark" label="备注" align="center" width="150"/>
    </el-table>
    <pagination
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listCashTotal,listCashDetail,listCustomerTotal} from "../../../../api/payMng";

export default {
  dicts: ['sys_trade_status', 'sys_trade_type','sys_yes_no','ims_payment_type'],
  data() {
    return {
      tabIndex:'0',
      loading: false,
      list: [],
      form: {
        accountInfo: "",
        customerName: "",
        time:[],
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('form')
      this.handleQuery()
    },
    getList() {
      if(this.form.time&&this.form.time.length){
        this.form.startTime=this.form.time[0]
        this.form.endTime=this.form.time[1]
      }else{
        this.form.startTime=''
        this.form.endTime=''
      }
      if(this.tabIndex==0){
        this.loading = true
        listCustomerTotal(this.form).then(res => {
          this.list = res.rows
          this.total = res.total
        }).finally(e => {
          this.loading = false
        })
      }
      else if(this.tabIndex==1){
        this.loading = true
        listCashTotal(this.form).then(res => {
          this.list = res.rows
          this.total = res.total
        }).finally(e => {
          this.loading = false
        })
      }else{
        this.loading = true
        listCashDetail(this.form).then(res => {
          this.list = res.rows
          this.total = res.total
        }).finally(e => {
          this.loading = false
        })
      }
    }
  }
}
</script>
